package service.Impl;

import dao.ArauditorDetailsDao;
import dao.InoutDao;
import dao.RepertoryDao;
import entity.Inout;
import entity.Repertory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import pojo.xiaoshou;
import service.RepertorySDao;
@Service
public class RepertorySImpl implements RepertorySDao {
    @Autowired
    public RepertoryDao repertoryDao;
    @Autowired
    public InoutDao inoutDao;
    @Autowired
    public ArauditorDetailsDao arauditorDetailsDao;
    @Override
    /**
     * 商品变动信息录入
     */
    public void upkucun(int repertoryId, double price) {
        //根据商品编号查询该商品信息
        Repertory repertory=repertoryDao.showRepertoryId(repertoryId);
        //根据商品编号查询该商品最近改动的日期
        Inout inout=inoutDao.showInoutTime(repertoryId);
        //根据最近改动的日期和商品编号查询当今天的销售数量和销售额
        xiaoshou xiao=null;
        if(inout!=null){
           xiao =arauditorDetailsDao.showNumAndSum(repertoryId,inout.getInouttime());
        }else{
            xiao=arauditorDetailsDao.showNumAndSum(repertoryId,null);
        }
        Inout inouts=new Inout();
        inouts.setRepertoryId(repertoryId);//商品编号
        inouts.setInoutNum(repertory.getRepertoryNum());//剩余库存量
        inouts.setSellNum(xiao.getNum());//销售量
        inouts.setLastprice(repertory.getPrice());//上次进价
        inouts.setPreinstall(repertory.getPresetPrice());//预设价格
        inouts.setTheprice(price);//本次进价
        inouts.setThepricestall(price*0.2+price);//本次卖价
        inouts.setAverage((price*repertory.getRepertoryNum())-(repertory.getPresetPrice()*repertory.getRepertoryNum()));//总盈利/总亏损
        inoutDao.addInout(inouts);//添加库存变动
        repertoryDao.upprice(repertoryId,price);//修改商品进价
    }
}
